{include file="/sum/common/script" /}
<style>
    .handle-popover .tip {
        margin-bottom: 16px;
    }

    .question-filled {
        color: var(--el-color-warning);
        margin-right: 4px;
    }
</style>

<div id="index" class="store-index panel panel-default panel-intro" v-cloak>
    <el-container class="panel-block">
        <el-header class="sa-header">

            <div class="sa-title sa-flex sa-row-between">
                <div class="sa-title-left">
                    <div class="left-name">商户列表</div>
                    <sa-filter-condition v-model="state.filter" @filter-delete="onChangeFilter">
                    </sa-filter-condition>
                </div>
                <div class="sa-title-right">
                    <el-button class="sa-button-refresh" icon="RefreshRight" @click="getData"></el-button>
                    <el-button class="sa-button-refresh" icon="Search" @click="onOpenFilter"></el-button>

<!--                    {if $auth->check('sum/store/store/add')}-->
<!--                    <el-button icon="Plus" type="primary" @click="onAdd">添加</el-button>-->
<!--                    {/if}-->
                    {if $auth->check('sum/store/store/recyclebin')}
                    <el-button type="danger" icon="Delete" plain @click="onRecyclebin">回收站</el-button>
                    {/if}
                </div>
            </div>
        </el-header>
        <el-main class="sa-main">
            <el-table height="100%" class="sa-table" :data="state.data" stripe @selection-change="onChangeSelection" @sort-change="onChangeSort">
                <el-table-column type="selection" width="48" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" min-width="90" sortable="custom">
                </el-table-column>
                <el-table-column prop="style" label="商户logo" min-width="120">
                    <template #default="scope">
                        <sa-image class="goods-image" :url="scope.row.image" size="64"></sa-image>
                    </template>
                </el-table-column>
                <el-table-column label="商户名称" min-width="166">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.store_name }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="所属用户" min-width="158">
                    <template #default="scope">
                        <sa-user-profile :user="scope.row.user" :id="scope.row.user_id"></sa-user-profile>
                    </template>
                </el-table-column>
                <el-table-column label="联系人" min-width="132">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.user_name }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="联系电话" min-width="130">
                    <template #default="scope">
                        <div class="sa-table-line-1">
                            {{ scope.row.phone }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="代理人" min-width="158">
                    <template #default="scope">
                        <sa-user-profile :user="scope.row.agent" :id="scope.row.agent_id"></sa-user-profile>
                    </template>
                </el-table-column>
                <el-table-column label="创建时间" width="172">
                    <template #default="scope">
                        {{ scope.row.createtime || '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="更新时间" width="172">
                    <template #default="scope">
                        {{ scope.row.updatetime || '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="状态" min-width="80">
                    <template #default="scope">
                        <el-tag :type="scope.row.status == 'normal' ? 'success' : 'info'">
                            {{ scope.row.status_text }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column fixed="right" label="操作" min-width="480">
                    <template #default="scope">
                        {if $auth->check('sum/store/goods')}
                        <el-button type="primary" link @click="onGoods(scope.row.id,scope.row.store_name)">商品</el-button>
                        {/if}

                        {if $auth->check('sum/store/user/index')}
                        <el-button type="primary" link @click="onUser(scope.row.id,scope.row.store_name)">员工管理</el-button>
                        {/if}

                        {if $auth->check('sum/store/order/index')}
                        <el-button type="primary" link @click="onOrder(scope.row.id,scope.row.store_name)">店铺订单</el-button>
                        {/if}

                        {if $auth->check('sum/store/activity/activity/index')}
                        <el-button type="primary" link @click="onActivity(scope.row.id,scope.row.store_name)">拼团活动</el-button>
                        {/if}

                        {if $auth->check('sum/store/stock_order/index')}
                        <el-button type="primary" link @click="onStockOrder(scope.row.id,scope.row.store_name)">进货订单</el-button>
                        {/if}

                        {if $auth->check('sum/store/store/edit')}
                        <el-button type="primary" link @click="onEdit(scope.row.id)">编辑</el-button>
                        {/if}
                        <el-popconfirm width="fit-content" confirm-button-text="确认" cancel-button-text="取消"
                                       title="确认删除这条记录?" @confirm="onDelete(scope.row.id)">
                            <template #reference>
                                {if $auth->check('sum/store/store/delete')}
                                <el-button type="danger" link>删除</el-button>
                                {/if}
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </el-table>
        </el-main>
        <el-footer class="sa-footer sa-flex sa-row-between sa-flex-wrap">
            <div class="sa-batch sa-flex">
                <div class="tip">
                    已选择 <span>{{batchHandle.data.length}}</span> 项</div>
                <div class="sa-flex">
                    {if $auth->check('sum/store/store/delete')}
                    <el-button type="danger" :disabled="!batchHandle.data.length" @click="onBatchHandle('delete')">删除
                    </el-button>
                    {/if}
                    {if $auth->check('sum/store/store/edit')}
                    <el-button type="success" :disabled="!batchHandle.data.length" @click="onBatchHandle('normal')">正常
                    </el-button>
                    <el-button type="info" :disabled="!batchHandle.data.length" @click="onBatchHandle('hidden')">隐藏
                    </el-button>
                    {/if}
                </div>
            </div>
            <sa-pagination v-model="pagination" @pagination-change="getData"></sa-pagination>
        </el-footer>
    </el-container>
    <sa-filter v-model="state.filter" @filter-change="onChangeFilter"></sa-filter>
</div>